var httpsUrl = getApp().globalData.httpsUrl;
var globalData = getApp().globalData;
var commonUtil = require("../../../utils/commonUtil.js")
var imgUrl = globalData.imgUrl;
var model = require('../../../model/model.js')
var show = false;
var item = {};
Page({
  data: {
    imgUrl: imgUrl,
    info: new Object(),
    item: {show: show},
  },
  //加载
  loadData: function () {
    let info = wx.getStorageSync("addressInfo");
    if (info != undefined && info != ''){
      this.setData({ info: info })
    }
  },

  //保存
  save: function (e) {
    let info = this.data.info;
    var frm = e.detail.value;//form内容
    frm.isDefault = info.is_default;
    let url = "";
    if (info.id == undefined || info.id == null || info.id == ""){
      url = "/memberAddress/addAddress";
      frm.isDefault = false;
    }else{
      frm.id = info.id;
      url = "/memberAddress/editAddress";
    }
    console.log("参数：" + JSON.stringify(frm));
    commonUtil.showLoading("请稍等...");
    let openId = wx.getStorageSync("openidKey");
    wx.request({
      header: { "openId": openId, },
      url: httpsUrl + url,
      dataType: "json",
      method: "POST",
      data: frm,
      success: function (res) {
        commonUtil.hideLoading();
        console.log("res：" + JSON.stringify(res));
        res = res.data;
        if (res.result == 0) {
          wx.navigateBack({
            delta: 1
          })
        }else {
          commonUtil.showModal(res.msg);
        }
      }
    })
  },
  //点击选择城市按钮显示picker-view
  translate: function (e) {
    model.animationEvents(this, 0, true, 400);
  },
  //隐藏picker-view
  hiddenFloatView: function (e) {
    model.animationEvents(this, 200, false, 400);
  },
  //滑动事件
  bindChange: function (e) {
    model.updateAreaData(this, 1, e);
    item = this.data.item;
    this.setData({
      province: item.provinces[item.value[0]].name,
      city: item.citys[item.value[1]].name,
      county: item.countys[item.value[2]].name
    });
    let info = this.data.info;
    info.area = item.provinces[item.value[0]].name + item.citys[item.value[1]].name + item.countys[item.value[2]].name;
    this.setData({info:info})
  },
  onLoad: function (options) {
    this.loadData();
  },
  onReady: function (e) {
    var that = this;
    model.updateAreaData(that, 0, e);//请求数据
  },
  nameCg:function(e){
    let info = this.data.info;
    info.name = e.detail.value;
    this.setData({ info: info, })
  },
  phoneCg: function (e) {
    let info = this.data.info;
    info.phone = e.detail.value;
    this.setData({ info: info, })
  },
  addressCg: function (e) {
    let info = this.data.info;
    info.address = e.detail.value;
    this.setData({ info: info, })
  },

})